package com.dididoctor.doctor.Activity.Main.Inquiry.InquiryDetail;

import android.content.Context;

import com.dididoctor.doctor.Activity.ConstantValue;
import com.dididoctor.doctor.Bean.Token;
import com.dididoctor.doctor.Http.MyHttpResponseHandler;
import com.dididoctor.doctor.MV.BasePresenter;
import com.dididoctor.doctor.MV.BusinessClient;
import com.dididoctor.doctor.MV.Response;
import com.dididoctor.doctor.Utils.Util;
import com.loopj.android.http.RequestParams;

import org.apache.http.Header;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @version 2.0
 * @类描述：
 * @项目名称：ddgh
 * @类名称： InquiryDetailPresenter
 * @包名称： com.dididoctor.doctor.Activity.Main.Inquiry.InquiryDetail
 * @创建人： zhanjunjie
 * @创建时间：2016/4/20 13:56
 * @修改人：
 * @修改时间：2016/4/20 13:56
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
public class InquiryDetailPresenter extends BasePresenter {

    private InquiryDetailView view;

    public InquiryDetailPresenter(Context context, InquiryDetailView view) {
        super(context, view);
        this.view = view;
    }

    public void getInqDet(String diseId) {
        RequestParams params = new RequestParams();
        params.put("userId", Token.getUserId());
        params.put("token", Token.getToken());
        params.put("diseId", diseId);
        BusinessClient.post(ConstantValue.disequs, params, new MyHttpResponseHandler() {
            private List<InquiryDetail> inquiryDetails = new ArrayList<InquiryDetail>();
            private List<Map<String, String>> maps = new ArrayList<Map<String, String>>();

            @Override
            public void onMyResponse(Response response) {
                if (response.isSucceed()) {
                    maps = response.getListData("quslist");
                    for (Map<String, String> map : maps) {
                        InquiryDetail inquiryDetail = new InquiryDetail();
                        inquiryDetail.setContent(Util.toString(map.get("content")));
                        inquiryDetail.setQusId(Util.toString(map.get("qusId")));
                        inquiryDetail.setIsSys(Util.toString(map.get("isSys")));
                        inquiryDetail.setType(Util.toString(map.get("type")));
                        inquiryDetail.setOptions(Util.toString(map.get("options")));
                        inquiryDetails.add(inquiryDetail);
                    }
                    view.getinqDet(inquiryDetails);
                } else {
//                    view.showToastMessage(response.getMsg());
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                super.onFailure(i, headers, bytes, throwable);
                view.getinqDetFail();
            }
        });
    }

    /**
     * @param qusId 问题id  用于2/3
     */
    public void qusoperate(String qusId) {
        RequestParams params = new RequestParams();
        params.add("userId", Token.getUserId());
        params.add("token", Token.getToken());
        params.add("optype", "3");
        params.add("qusId", qusId);
        params.add("diseId", "");
        params.add("type", "");
        params.add("options", "");
        params.add("content", "");
        BusinessClient.post(ConstantValue.qusoperate, params, new MyHttpResponseHandler() {

            @Override
            public void onMyResponse(Response response) {
                if (response.isSucceed()) {
                    view.DeleQuestionSucced();
                } else {
                    view.showToastMessage(response.getMsg());
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                super.onFailure(i, headers, bytes, throwable);
                view.DeleQuestionFail();
            }
        });
    }
}
